#include <stdio.h>
#include "jframework.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *replace(const char *source, const char *oldValue, const char *newValue)
{
	char *ret;
	int i, count = 0;
	size_t newlen = strlen(newValue);
	size_t oldlen = strlen(oldValue);

	for (i = 0; source[i] != '\0'; i++) {
		if (strstr(&source[i], oldValue) == &source[i]) {
			count++;
			i += oldlen - 1;
		}
	}

	ret = new char[i + count * (newlen - oldlen) + 1];

	if (ret == NULL)
		exit(EXIT_FAILURE);

	i = 0;
	while (*source) {
		if (strstr(source, oldValue) == source) {
			strcpy(&ret[i], newValue);
			i += newlen;
			source += oldlen;
		} else
			ret[i++] = *source++;
	}
	ret[i] = '\0';

	return ret;
}

int main(void)
{
	

	return 0;
}

// http://msdn.microsoft.com/en-us/library/ms235627(v=vs.80).aspx